package leetcode;
/**
 * 165.比较版本号
 */
public class Num_165 {
    public int compareVersion(String version1, String version2) {
        String[] s1 = version1.split("\\.");
        String[] s2 = version2.split("\\.");
        int num1,num2 = 0;
        for(int i = 0; i < Math.max(s1.length, s2.length); i++){
            //考虑是否有一个数组越界的情况
            if(i < s1.length){
                num1 = Integer.parseInt(s1[i]);
            }else{
                num1 = 0;
            }
            if(i < s2.length){
                num2 = Integer.parseInt(s2[i]);
            }else{
                num2 = 0;
            }
            //比较修订号
            if(num1 > num2){
                return 1;
            }else if(num1 < num2){
                return -1;
            }
        }
        return 0;
    }
}
